package com.jing.cloud.service.user.dao.impl;

import com.jing.cloud.service.dao.impl.DbDaoImpl;
import com.jing.cloud.service.user.bean.Ticket;
import com.jing.cloud.service.user.dao.TicketDao;
import com.jing.cloud.service.util.db.Compare;
import org.apache.curator.shaded.com.google.common.collect.Maps;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


@Repository
public class TicketDaoImpl extends DbDaoImpl<Ticket> implements TicketDao {

    @Override
    public Ticket getByTicketStr(String ticketStr) {
        Map<String, Object> condition = Maps.newHashMap();
        condition.put("ticketStr", ticketStr);
        condition.put("ticketHash", (long) ticketStr.hashCode());
        List<Ticket> tickets = query(condition);
        if (tickets == null || tickets.isEmpty()) {
            return null;
        }
        return tickets.get(0);
    }

    @Override
    public List<Ticket> getListByUserIds(List<Long> userIds) {
        Map<String, Object> condition = Maps.newHashMap();
        Compare c = new Compare();
        c.setIn(userIds);
        condition.put("userId", c);
        return query(condition);
    }
}
